﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 三国杀
{
    public partial class QQMain : Form
    {
        public QQMain()
        {
            InitializeComponent();

        }
        Point mousePosition;

        Point formPosition;

        bool isMouseDown = false;//是否按下

        bool isMouseIn = false;//是否在窗体内
        private void FrmQQMain_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;

            mousePosition = Control.MousePosition;  //鼠标位置

            formPosition = this.Location;   //窗体左上角位置
        }

        private void FrmQQMain_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }

        private void FrmQQMain_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePoint = Control.MousePosition;   //移动的位置
            if (isMouseDown && isMouseIn) {
                this.Location = new Point(mousePoint.X - mousePosition.X + formPosition.X, mousePoint.Y - mousePosition.Y + formPosition.Y);
            }
        }

        private void FrmQQMain_MouseEnter(object sender, EventArgs e)
        {
            isMouseIn = true;
        }

        private void FrmQQMain_MouseLeave(object sender, EventArgs e)
        {
            isMouseIn = false;
        }

        private void FrmQQMain_Load(object sender, EventArgs e)
        {
            this.pictureBox1.BackgroundImage = this.qqimages.Images[0];
            MessageBox.Show(Userid);
            Iconshow();
        }
        // 在QQMain类中添加以下代码
        public List<FriendInfo> FriendsList = new List<FriendInfo>();

        public class FriendInfo
        {
            public int ImageIndex { get; set; }
            public string Name { get; set; }
            public string Signature { get; set; }
        }

        // 添加显示好友的方法
        public void DisplayFriends()
        {
            // 这里假设你有一个Panel或其他容器来显示好友列表
            // 你需要先在Designer中添加一个Panel控件，比如命名为panelFriends
            panelFriends.Controls.Clear();

            int yPos = 10;
            foreach (var friend in FriendsList)
            {
                // 创建好友头像PictureBox
                PictureBox pb = new PictureBox();
                pb.Image = qqimages.Images[friend.ImageIndex];
                pb.Size = new Size(60, 60);
                pb.Location = new Point(10, yPos);
                pb.SizeMode = PictureBoxSizeMode.StretchImage;

                // 创建好友名称Label
                Label nameLabel = new Label();
                nameLabel.Text = friend.Name;
                nameLabel.Location = new Point(80, yPos);
                nameLabel.AutoSize = true;

                // 创建签名Label
                Label sigLabel = new Label();
                sigLabel.Text = friend.Signature;
                sigLabel.Location = new Point(80, yPos + 25);
                sigLabel.AutoSize = true;
                sigLabel.ForeColor = Color.Gray;
                sigLabel.Font = new Font(sigLabel.Font, FontStyle.Italic);

                // 添加到Panel
                panelFriends.Controls.Add(pb);
                panelFriends.Controls.Add(nameLabel);
                panelFriends.Controls.Add(sigLabel);

                yPos += 70;
            }
        }


        public string Userid;
        public string password;
        //获取当前QQ的头像
        public void Iconshow()
        {
            if (string.IsNullOrEmpty(this.Userid))
            {
                MessageBox.Show("QQ变量未正确赋值，无法进行查询！");
                return;
            }
            DB db = new DB();
            try
            {
                db.dbOpen();
                string sql = "select * from QQUsers";
                SqlCommand comm = new SqlCommand(sql, db.Conn);
                SqlDataReader read = comm.ExecuteReader();
                while (read.Read())
                {
                    if (read["QQ"].ToString().Equals(Userid)&&read["Pwd"].ToString().Equals(password))
                    {
                        this.pictureBox1.BackgroundImage = this.qqimages.Images[Convert.ToInt32(read["imagenum"])];
                        this.txtname.Text = read["Name"].ToString();
                        this.qianming.Text = read["qianming"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void PictureBox2_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void PictureBox3_Click(object sender, EventArgs e)
        {
            new QQSearch().Show();
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            var ModifyId = new ModifyId();
            ModifyId.Userid = this.Userid;
            ModifyId.password = this.password;

            if (string.IsNullOrEmpty(ModifyId.Userid))
            {
                MessageBox.Show("变量未正确赋值，无法进行查询！");
                return;
            }

            // 显示修改窗体
            ModifyId.ShowDialog(); // 使用ShowDialog而不是Show

            // 修改窗体关闭后，刷新主窗体数据
            this.Iconshow();
            this.Show(); // 确保主窗体显示
        }

        private void pictureBox4_Click_1(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form is QQLogin)
                    form.Close();
            }
        }
    }
}
